package com.chen.base.module.redis.config;

import com.chen.base.module.redis.aop.LockAop;
import com.chen.base.module.redis.service.impl.CacheServiceImpl;
import com.chen.base.module.redis.service.impl.RedisLuaDistributedLock;
import com.chen.base.module.redis.service.impl.RedissonDistributedLock;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;

/**
 * @author: Long
 * @date: 2025/3/22 22:52
 **/
@Configuration
public class RedisAutoConfig {

    @Bean
    public RedisTemplateConfig redisTemplateConfig(){
        return new RedisTemplateConfig();
    }

    @Bean
    public RedissonConfig redissonConfig(){
        return new RedissonConfig();
    }

    @Bean
    public RedisCacheManagerConfig redisCacheManagerConfig(){
        return new RedisCacheManagerConfig();
    }

    @Bean
    public RedisCacheAutoConfiguration redisCacheAutoConfiguration(CacheProperties cacheProperties, CacheManagerCustomizers customizerInvoker,
                                                                   ObjectProvider<RedisCacheConfiguration> redisCacheConfiguration){
        return new RedisCacheAutoConfiguration(cacheProperties, customizerInvoker, redisCacheConfiguration);
    }

    @Bean
    public CacheServiceImpl cacheServiceImpl(){
        return new CacheServiceImpl();
    }

    @Bean
    public RedissonDistributedLock redissonDistributedLock(){
        return new RedissonDistributedLock();
    }

    @Bean
    public RedisLuaDistributedLock redisLuaDistributedLock(){
        return new RedisLuaDistributedLock();
    }

    @Bean
    public LockAop lockAop(){
        return new LockAop();
    }

    @Bean
    public RefreshCacheJob refreshCacheJob(){
        return new RefreshCacheJob();
    }

    @Bean
    public RedisQueueConfig redisQueueAutoConfig(){
        return new RedisQueueConfig();
    }

}
